package com.dq.Week3.day11;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateDemo {
    public static void main(String[] args) throws ParseException {
//        Date date = new Date(0);
//        System.out.println(date);
//
//        Date date1 = new Date(1000);
//        Date date2 = new Date();
//        System.out.println("date1:"+date1);
//        System.out.println("date2:"+date2);
//
//        boolean before = date2.before(date1);
//        System.out.println("before:"+before);
//
//        //创建对象时间时需要指定日期时间字符串的格式yyyy-MM-dd HH:mm:ss
//
//        //字符串转日期对象
//        String s= "2002-02-14 00:00:00";
//        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//        Date date3 = format.parse(s);
//        System.out.println("date3:"+date3);
//
//        //日期对象转字符串
//        Date date4 = new Date();
//        System.out.println("date4:"+date4);
//        String s2 = format.format(date2);
//        System.out.println("s2:"+s2);

        //获取时间的毫秒值


        String myBirthday = "2002-02-14 00:00:00";
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date parse = simpleDateFormat.parse(myBirthday);
        long startTime = parse.getTime();
        System.out.println("startTime:\t"+startTime);


        Date date5 = new Date();
        long nowTime = date5.getTime();
        System.out.println("nowTime:\t"+nowTime);

        long servive = nowTime - startTime;
        //按小时计算
        servive = servive/1000/60/60;

        System.out.println("您在地球online已经存活："+servive+"个小时了");


    }
}
